package org.willthink.dao.fileupload.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.collections.map.HashedMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;
import org.willthink.dao.fileupload.FileUploadDAO;
import org.willthink.vo.common.PagingValuesVo;
import org.willthink.vo.fileupload.FileUploadInfoVo;

import com.ibatis.sqlmap.client.SqlMapClient;

@Repository
public class FileUploadDAOImpl implements FileUploadDAO {
	
	private Logger logger = LoggerFactory.getLogger(getClass());
	
	private SqlMapClient sqlMapClient;
	
	public void setSqlMapClient(SqlMapClient sqlMapClient) {
		this.sqlMapClient = sqlMapClient;
	}

	@Override
	public void uplaodFilesDbInsert(FileUploadInfoVo fileUploadInfoVo) {
		// logger.debug(" : {}", );
		try {
			logger.debug("FileUploadDAOImpl sqlMapClient : {}", sqlMapClient);
			logger.debug("FileUploadDAOImpl fileUploadInfoVo : {}", fileUploadInfoVo);
			sqlMapClient.insert("FileUpload.uploadFileInsert", fileUploadInfoVo);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	@Override
	public int getUploadFileAllRow() {
		//
		int selectUploadFileAllRowCnt = 0;
		try {
			logger.debug("FileUploadDAOImpl sqlMapClient : {}", sqlMapClient);
			selectUploadFileAllRowCnt = (Integer) sqlMapClient.queryForObject("FileUpload.uploadFileAllRowCnt");
			logger.debug("FileUploadDAOImpl selectUploadFileAllRowCnt : {}", selectUploadFileAllRowCnt);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return selectUploadFileAllRowCnt;
	}

	@Override
	public ArrayList<FileUploadInfoVo> getUploadFileList(String firstRow, String endRow) {
		ArrayList<FileUploadInfoVo> uploadFileList = null;
		logger.debug("FileUploadDAOImpl sqlMapClient : {}", sqlMapClient);
		Map<String, String> selectParamMap = new HashMap<String, String>();
		selectParamMap.put("firstRow", firstRow);
		selectParamMap.put("endRow", endRow);
		try {
			uploadFileList = (ArrayList<FileUploadInfoVo>) sqlMapClient.queryForList("FileUpload.uploadFileList", selectParamMap);
			logger.debug("FileUploadDAOImpl uploadFileList : {}", uploadFileList);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return uploadFileList;
	}

	@Override
	public ArrayList<FileUploadInfoVo> getSearchFileList(String fileName) {
		ArrayList<FileUploadInfoVo> searchFileList = null;
		logger.debug("FileUploadDAOImpl sqlMapClient : {}", sqlMapClient);
		
		try {
			searchFileList = (ArrayList<FileUploadInfoVo>) sqlMapClient.queryForList("FileUpload.searchFileList", fileName);
			logger.debug("FileUploadDAOImpl uploadFileList : {}", searchFileList);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return searchFileList;
	}

	@Override
	public void deleteFile(int deleteNo) {
		
		try {
			sqlMapClient.delete("FileUpload.fileDelete", deleteNo);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}

	@Override
	public String getDeleteFileName(int no) {
		String deleteFileName = null;
		try {
			deleteFileName = (String) sqlMapClient.queryForObject("FileUpload.deleteFileName", no);
			logger.debug("FileUploadDAOImpl deleteFileName : {}", deleteFileName);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return deleteFileName;
	}

	

	
	
	

}
